using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace TrafficTrouble.Components
{
    public class History
    {
        private static Stack<HistoryItem> history;

        public static bool HasHistory { get { return history.Count > 0; } }
        public static HistoryItem GetLastMove()
        {
            if (history.Count > 0) return history.Pop();
            else throw new NoHistoryException("TrafficTroube.Components.History.GetLastMove()");
        }

        public static void AddMove(HistoryItem move)
        {
            history.Push(move);
        }

        public static void Reset()
        {
            history = new Stack<HistoryItem>();
        }
    }

    public struct HistoryItem
    {
        private Car _car;
        public Car Car { get { return this._car; } set { this._car = value; } }

        private Point _start, _end;
        public Point Start { get { return this._start; } set { this._start = value; } }
        public Point End { get { return this._end; } set { this._end = value; } }

        public HistoryItem(Car car, Point start, Point end)
        {
            this._car = car;
            this._start = start;
            this._end = end;
        }
    }

    public class NoHistoryException : Exception
    {
        public NoHistoryException(string source) : base("The player has made no previous moves. (" + source + ").") { }
    }
}
